package com.tianqu.tms.entity;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import com.tianqu.tms.core.base.TmsEntity;
import com.tianqu.tms.core.exception.TmsDaoException;
import com.tianqu.tms.core.exception.TmsException;
import com.tianqu.tms.dao.CommercialVehicleDao;
import com.tianqu.tms.dao.TmsDao;
import com.tianqu.tms.dto.CommercialVehicleDto;

/**
 * 商用车品牌字典表
 * 
 * @author Administrator
 * 
 */
public class CommercialVendor extends TmsEntity {

	/**
	 * 
	 */
	private static final long serialVersionUID = -4470220257158950456L;

	private String vendorId;// 品牌ID

	private String vendorName;// 品牌名

	private String country;// 国别

	private String firstChar;// 品牌首字母

	/**
	 * 实例化codes表
	 * 
	 * @return
	 */
	private static CommercialVendor instance;

	List<CommercialVendor> codes = null;

	/**
	 * 加载Codes
	 * 
	 * @return
	 * @throws TmsDaoException
	 */
	public static CommercialVendor getInstance() throws TmsDaoException {
		if (null == instance) {
			instance = new CommercialVendor();
			instance.init();
		}
		return instance;
	}

	/**
	 * 实例化Code
	 * 
	 * @throws TmsDaoException
	 */
	public void init() throws TmsDaoException {
		codes = new ArrayList<CommercialVendor>();
		setCodes();
	}

	/**
	 * 获取Codes信息存在静态codes中
	 * 
	 * @throws TmsDaoException
	 */
	public void setCodes() throws TmsDaoException {
		CommercialVehicleDao dao = (CommercialVehicleDao) TmsDao
				.getInstance(TmsDao.TMS_COMMERCIAL_VEHICLE);
		List<CommercialVehicleDto> list = dao.findAllCommercialVendorInfo();
		for (int i = 0; i < list.size(); i++) {
			CommercialVehicleDto dto = (CommercialVehicleDto) list.get(i);
			CommercialVendor entity = new CommercialVendor();
			entity.setVendorId(dto.getVendorId());
			entity.setVendorName(dto.getVendorName());
			codes.add(entity);
		}
	}

	/**
	 * 获取下拉列表
	 * 
	 * @return
	 */
	@SuppressWarnings("unchecked")
	public List findAllVendorInfo() {
		List list = new ArrayList();
		Map map = null;
		for (int i = 0; i < codes.size(); i++) {
			CommercialVendor vendor = codes.get(i);
			map = new HashMap();
			map.put("vendorId", vendor.getVendorId());
			map.put("vendorName", vendor.getVendorName());
			list.add(map);
		}
		return list;
	}

	public String getVendorId() {
		return vendorId;
	}

	public void setVendorId(String vendorId) {
		this.vendorId = vendorId;
	}

	public String getVendorName() {
		return vendorName;
	}

	public void setVendorName(String vendorName) {
		this.vendorName = vendorName;
	}

	public String getCountry() {
		return country;
	}

	public void setCountry(String country) {
		this.country = country;
	}

	public String getFirstChar() {
		return firstChar;
	}

	public void setFirstChar(String firstChar) {
		this.firstChar = firstChar;
	}

	@Override
	public void save() throws TmsDaoException, TmsException {
		// TODO Auto-generated method stub

	}

}
